/**
 * 
 */
package py.edu.ucom.cadira.net.serializables;

import org.jdom.Document;
import org.jdom.Element;
import py.edu.ucom.cadira.game.war.Movement;
import py.edu.ucom.cadira.net.XMLSerializable;

/**
 * @author largonet
 * 
 */
public class MoveFichaRequest implements XMLSerializable {
    private static final String NODE_MOVE_TAB = "moveFicha";
    private Movement mov;
    private Integer mesaId;

    public MoveFichaRequest() {
        mov = new Movement();
    }
    /**
     * @return Returns the mesaId.
     */
    public Integer getMesaId() {
        return mesaId;
    }
    /**
     * @param mesaId
     *            The mesaId to set.
     */
    public void setMesaId(Integer mesaId) {
        this.mesaId = mesaId;
    }
    /**
     * @return Returns the mov.
     */
    public Movement getMov() {
        return mov;
    }
    /**
     * @param mov
     *            The mov to set.
     */
    public void setMov(Movement mov) {
        this.mov = mov;
    }
    public void fromXML(Document xml) {
        Element root = xml.getRootElement();
        Element moveNode = root.getChild(NODE_MOVE_TAB);
        Element tableNode = moveNode.getChild("table");
        setMesaId(Integer.valueOf(tableNode.getAttributeValue("id")));
        mov.fromXml(tableNode);
    }
    public void toXML(Element root) {
        Element moveNode = new Element(NODE_MOVE_TAB);
        Element tableNode = new Element("table");
        tableNode.setAttribute("id", getMesaId().toString());
        mov.toXml(tableNode);
        moveNode.addContent(tableNode);
        root.addContent(moveNode);
    }
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof MoveFichaRequest)) {
            return false;
        }
        MoveFichaRequest otherObj = (MoveFichaRequest) obj;
        if (otherObj.getMesaId().equals(this.getMesaId())) {
            return true;
        }
        return false;
    }
}
